package tech.xs.common.framework.config.mybatis;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import tech.xs.common.framework.config.WorkId;
import tech.xs.common.framework.init.InitExecute;

import javax.annotation.Resource;

@Component
@Order(100)
public class MybatisIdGenerator implements IdentifierGenerator, InitExecute {

    @Resource
    private WorkId workId;

    @Override
    public Number nextId(Object entity) {
        return IdUtil.nextId();
    }

    @Override
    public void execute() throws Exception {
        IdUtil.setWorkerId(workId.getWorkId());
    }

    @Override
    public boolean isErrorStop() {
        return true;
    }

}
